#!/usr/bin/env python

from optparse import OptionParser
import sys

from megahal import *

def main(argv=None):
    optparse = OptionParser(version=__version__, description=__doc__)
    optparse.add_option('-b', '--brain', dest='brainfile', metavar='<file>', default=DEFAULT_BRAINFILE,
                        help='location of brain (default: %default)')
    optparse.add_option('-o', '--order', metavar='<int>', default=DEFAULT_ORDER, type='int',
                        help='order of markov chain (default: %default)')
    optparse.add_option('-t', '--timeout', metavar='<float>', default=DEFAULT_TIMEOUT, type='float',
                        help='how long to look for replies (default: %default)')
    optparse.add_option('-T', '--train', metavar='<file>', help='train brain with file')
    opts, args = optparse.parse_args(argv)

    megahal = MegaHAL(brainfile=opts.brainfile, order=opts.order, timeout=opts.timeout)
    if opts.train:
        megahal.train(opts.train)
    megahal.interact()

    return 0

if __name__ == '__main__':
    sys.exit(main())
